package com.example.supermarket.controller;

import com.alibaba.fastjson.JSONArray;
import com.example.supermarket.entity.Order;
import com.example.supermarket.entity.OrderAndGoods;
import com.example.supermarket.mapper.OrderMapper;
import com.example.supermarket.service.AdminOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>会员消费记录模块</p>
 * @author Bosen
 * @date 2021/10/13 11:33
 */
@RestController
public class AdminOrderController {

    @Autowired
    AdminOrderService service;

    @Autowired
    OrderMapper orderMapper;

    /**
     * <p>消费管理页面</p>
     */
    @RequestMapping("/admin/order")
    public ModelAndView order(ModelAndView modelAndView) {
        List<OrderAndGoods> order = service.getOrderAndGoodsList();
        String orderJson = JSONArray.toJSONString(order);
        modelAndView.addObject("orderJson",orderJson);
        modelAndView.setViewName("admin/order");
        return modelAndView;
    }

    /**
     * <p>修改支付状态</P>
     * @Date 2021/10/14 22:14
     */
    @RequestMapping("/admin/update/orderpay")
    public int updateOrderpay(int flag, String orderId){
        return  orderMapper.updateOrder(orderId,flag,System.currentTimeMillis());
    }

    /**
     * <p>删除订单</P>
     * @Date 2021/10/14 22:20
     */
    @RequestMapping("/admin/del/order")
    public int delorder(int id){
        return orderMapper.deleteById(id);
    }
}
